import fetch from "../../utils/fetch";
import { addZero } from "../../utils/util";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //活动报名即将结束
    quickEndActArr:[
      {
        id:1,
        title:'好春光，不如走一场',
        img:'http://localhost:8080/images/admin/taqing2.png',
        startDate:'2015-12-15 9:00',
        endDate:'2015-12-15 17:00',
        startJoin:'2015-12-10 20:00',
        endJoin:'2015-12-13 20:00',
        content:'asdaasda'
      },
      
    ],
    //活动数据
    activityArr:[
      {
        id:1,
        title:'好春光，不如走一场',
        img:'http://localhost:8080/images/admin/taqing2.png',
        startDate:'2024-03-15 9:00',
        endJoin:'2015-03-13 20:00',
      },
    ],
    page:1, //活动页码
    actCount:0, //活动数量

    city:'城市',
    todayDate:'',  //今天日期
  },
  size:10,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //获取活动列表
    let todayDate = new Date();
    todayDate = todayDate.getFullYear() + '-' + addZero(todayDate.getMonth()+1) + '-' + addZero(todayDate.getDate());
    this.getActList(1,this.data.page,this.size,todayDate).then(res=>{
      console.log(res);
      res.data.activitys.forEach(item=>{
        item.endJoin = item.endJoin1 + ' ' + item.endJoin2;
      })
      this.setData({
        quickEndActArr:res.data.quickEndActs,
        activityArr:res.data.activitys,
        actCount:res.data.count,
        todayDate:todayDate
      })
    })
  },
  //获取活动列表
  getActList(type,page,size,todayDate,city='城市'){
    return fetch('/activity/list',{
      type,page,size,todayDate,city
    });
  },
  selectCity(e){
    const city = e.detail.value[1]
    this.setData({
      city,
    });
    //获取城市活动数据
    this.data.page = 1;
    this.data.actCount = 0;
    fetch('/activity/list',{
      type:2,
      page:this.data.page,
      size:this.size,
      todayDate:this.data.todayDate,
      city:city
    }).then(res=>{
      res.data.activitys.forEach(item=>{
        item.endJoin = item.endJoin1 + ' ' + item.endJoin2;
      })
      this.setData({
        activityArr:res.data.activitys,
        actCount:res.data.count
      })
    })
  },
  gotoActDetail(e){
    const actId = e.currentTarget.dataset.actId;
    wx.navigateTo({
      url: '../../pages/activityDetail/activityDetail?actId=' + actId,
    })
  },
  getMoreArticle(){
    //获取更多活动
    if( this.data.page*this.size > this.data.actCount){
      return;
    }
    this.data.page++;
    this.getActList(2,this.data.page,this.size,this.data.todayDate,this.data.city).then(res=>{
      let activityArr = this.data.activityArr;
      res.data.activitys.forEach(item=>{
        item.endJoin = item.endJoin1 + ' ' + item.endJoin2
        activityArr.push(item);
      });
      this.setData({
        activityArr,
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})